package com.lucky.auth_boot.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.lucky.auth_boot.pojo.dto.UserDTO;
import com.lucky.auth_boot.pojo.po.SystemConfigPO;
import com.lucky.auth_boot.mapper.SystemConfigMapper;
import com.lucky.auth_boot.pojo.vo.SystemConfigVO;
import com.lucky.auth_boot.service.SystemConfigService;
import com.lucky.auth_boot.utils.ThreadLocalUtil;
import jakarta.annotation.Resource;
import org.springframework.security.core.context.SecurityContextHolder;
import org.springframework.stereotype.Service;

import java.util.Date;

@Service
public class SystemConfigServiceImpl implements SystemConfigService {

    @Resource
    SystemConfigMapper systemConfigMapper;

    @Override
    public Integer putSiteSettings(SystemConfigPO config) {
//        UserPO userPO = ThreadLocalUtil.get();
        UserDTO userDTO = (UserDTO) SecurityContextHolder.getContext().getAuthentication().getPrincipal();

        config.setUpdater(userDTO.getId());
        config.setUpdateTime(new Date());
        config.setCreateTime(null);
        config.setCreateTime(null);
        QueryWrapper<SystemConfigPO> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("id", 1);
        systemConfigMapper.update(config,queryWrapper);
        return 0;
    }

    @Override
    public SystemConfigVO getSiteSettings() {
        return systemConfigMapper.getSiteSettings();
    }
}
